<?php
namespace app\admin\controller;
use app\common\controller\Adminbase;
use \think\Db;
use \think\Loader;

// +----------------------------------------------------------------------
// | XpCms
// +----------------------------------------------------------------------
// | Copyright (c) 2021-2099
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Mercurio（Xp） <725668993@qq.com>
// +----------------------------------------------------------------------

/*
** 后台首页
*/

class Index extends Adminbase {
	private static $_menu = null; // 数据表对象
	
	// 优先加载
	public function  _initialize() {
		self::$_menu = Loader::model('Menu');
		parent::_initialize();
		
	}
	
	public function index() {
		
		$this -> assign('sysinfo', $this -> sysinfo());
		return view('index');
	}
	
	public function welcome() {
	    $cate_num = Db::name('category')->count();
	    $message_num = Db::name('message')->where('status', 0)->count();
	    $this -> assign('messagenum', $message_num);
	    $this -> assign('catenum', $cate_num);
	    $this -> assign('sysinfo', $this -> sysinfo());
		return view('welcome');
	}
	
	//清除缓存
    public function clear(){
        cache('Menu', null);
		$data = self::$_menu -> menuLists();
		cache('Menu', $data);
        $result['msg'] = '清除缓存成功!';
        $result['code'] = 1;
        $result['url'] = url('admin/index/welcome');
        return $result;
    }
	
	
	// 系统信息
	private function sysinfo() {
		//$mysql = M() -> query('select VERSION() as version');
		//$mysql = $mysql[0]['version'];
		$mysql = empty($mysql) ? '未知' : $mysql;
		
		return array(
			'操作系统' 		=> PHP_OS,
			'运行环境' 		=> $_SERVER["SERVER_SOFTWARE"],
			'PHP 运行方式' 	=> php_sapi_name(),
			'PHP 版本' 		=> PHP_VERSION,
			'MYSQL 版本' 	=> $mysql,
			'上传附件限制' 	=> ini_get('upload_max_filesize'),
			'执行时间限制' 	=> ini_get('max_execution_time') . 's',
			'剩余空间' 		=> round((@disk_free_space('.') / (1024 * 1024)), 2) . 'M',
		);
	}
	
}
